package com.zs.grain.ui

import android.app.Application
import androidx.lifecycle.MutableLiveData
import com.xnkj1688.semplibrary.mvvm.BaseViewModel
import com.zs.grain.service.*

import javax.inject.Inject

/**
 * Created by Wesley on 2017/7/17.
 */

class ComponentViewModel @Inject constructor(
    val mApp: Application,
    val mDeviceService: DeviceService,
    val mDataService: DataService
) : BaseViewModel(mApp) {

    val testInfoViewModels = MutableLiveData<MutableList<TestItemViewModel>>()
    val adjustmentViewModels = MutableLiveData<MutableList<TestItemViewModel>>()

    var componentId: Int = 0

    init {
    }

    fun init(componentId: Int) {
        this.componentId = componentId
        var testInfos = mDeviceService.getTestInfos(componentId)
        var list = ArrayList<TestItemViewModel>()
        if (testInfos != null) {
            for (item in testInfos) {
                var model = TestItemViewModel(mApp)
                model.id = item.index
                model.name = item.name
                model.componentId = componentId
                list.add(model)
            }
        }
        testInfoViewModels.value = list

        var adjustments = mDeviceService.getAdjustments(componentId)
        var list2 = ArrayList<TestItemViewModel>()
        if (adjustments != null) {
            for (item in adjustments) {
                var model = TestItemViewModel(mApp)
                model.id = item.id
                model.name = item.title
                model.componentId = componentId
                list2.add(model)
            }
        }
        adjustmentViewModels.value = list2
    }

    fun onClickTestInfo(vm: TestItemViewModel) {
        mDeviceService.testComponent(vm.componentId, vm.id)
    }

    fun onClickAdjustment(vm: TestItemViewModel) {

    }
}
